<template>
    <div>
        <el-breadcrumb separator-class="el-icon-arrow-right">
            <el-breadcrumb-item :to="{ path: '/index' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item>系统中心</el-breadcrumb-item>
            <el-breadcrumb-item>课程管理</el-breadcrumb-item>
        </el-breadcrumb>
        <el-card class="box-card">

            <el-button  type="primary" @click="dialogVisible = true">添加课程</el-button>

            <el-table
                    :data="classList"
                    style="width: 100%">
                <el-table-column
                        type="index"
                        width="50">
                </el-table-column>
                <el-table-column
                        prop="studentName"
                        label="学生姓名"
                        width="100">
                </el-table-column>
                <el-table-column
                        prop="teacherName"
                        label="教师姓名"
                        width="100">
                </el-table-column>
                <el-table-column
                        prop="subjectName"
                        label="课程名字"
                        width="140">
                </el-table-column>
                <el-table-column
                prop="classDate"
                label="上课日期"
                width="140">
                </el-table-column>
                <el-table-column
                        prop="beginTime"
                        label="上课时间"
                        width="140">
                </el-table-column>
                <el-table-column
                        prop="endTime"
                        label="下课课时间"
                        width="140">
                </el-table-column>
                <el-table-column
                        prop="classStatus"
                        label="课程状态"
                        width="100">
                    <template slot-scope="scope">
                        {{scope.row.classStatus|classStatusFit}}
                    </template>
                </el-table-column>
                <el-table-column
                        label="操作"
                        width="320">
                    <!--点击按钮 需要绑定@click的时间 例如 @click="add"-->
                    <template slot-scope="scope">
                        <el-button type="primary" size="mini" @click="(scope.row.id)">修改</el-button>
                        <el-button type="primary" size="mini" @click="(scope.row.id)">取消</el-button>
                    </template>
                </el-table-column>
            </el-table>
            <div class="block">
                <el-pagination
                        @size-change="handleSizeChange"
                        @current-change="handleCurrentChange"
                        :current-page="page.pageCurrent"
                        :page-sizes="[5, 10, 15, 20]"
                        :page-size="page.pageSize"
                        layout="total, sizes, prev, pager, next, jumper"
                        :total="total">
                </el-pagination>
            </div>
        </el-card>
        <el-dialog
                title="添加课程"
                :visible.sync="dialogVisible"
                width="30%">
            <el-form ref="form" :model="classForm" label-width="80px" >

            </el-form>
            <span slot="footer" class="dialog-footer">
                <el-button @click="clearClass">取 消</el-button>
                 <el-button type="primary" @click="addClass">确 定</el-button>
            </span>
        </el-dialog>

        <el-dialog
                title="编辑课程"
                :visible.sync="dialogVisible1"
                width="30%">
            <el-form ref="form" :model="classForm" label-width="80px" >
            </el-form>
            <span slot="footer" class="dialog-footer">
                <el-button @click="clearClass">取 消</el-button>
                 <el-button type="primary" @click="updateClass">确 定</el-button>
            </span>
        </el-dialog>


    </div>
</template>

<script>
import moment from 'moment'
    export default {
        name: "AdminList",
        data(){
            return{
                classList:[],
                classForm:{},
                dialogVisible:false,
                dialogVisible1:false,
                classid:null,
                page:{
                    pageCurrent:0,
                    pageSize:5
                },
                total:0,
            }
        },
        methods:{
            //实现分页
            //每页记录数
            handleSizeChange:function(val){
                this.page.pageSize = val
                this.classSel()
            },
            //当前页
            handleCurrentChange:function(val){
                this.page.pageCurrent = val
                this.classSel()
            },

            //列表实现
            classSel:function () {
                this.$http.post('/admin/classList?pageCurrent='+this.page.pageCurrent+
                    '&pageSize='+this.page.pageSize).then((res)=>{
                    this.classList = res.data.result.classPage.records;
                    this.total =  res.data.result.classPage.total;
                })
            },

            //逻辑删除
            delById:function (id) {
                this.$http.post('/admin/delSellerUser?id='+id).then((res)=>{
                    if (res.data.success) {
                        this.$message({
                            message: res.data.message,
                            type: 'success'
                        });
                    }
                    this.classSel();
                })
            },

            //添加课程
            addClass:function(){

            },

            updateClass:function(){

            },
            
            //清空表单
            clearClass:function(){
                this.dialogVisible=false
                this.dialogVisible1=false
                this.classSel()
            }

        },
        //过滤器
        filters:{
            classStatusFit:function (val) {
                if (val == '0'){
                    return "正常"

                }
                if (val == '1'){
                    return "弃用"
                }
            },
        },
        mounted() {
            this.classSel();
        }
    }
</script>

<style scoped>

</style>
